package tabela;
import java.awt.Component;

import javax.swing.BorderFactory;
import javax.swing.JProgressBar;
import javax.swing.JTable;
import javax.swing.table.DefaultTableCellRenderer;

public class TabelaArquivosProgressRenderer extends DefaultTableCellRenderer {
	
	private static final long serialVersionUID = 1L;
	public JProgressBar progressBar = new JProgressBar(0, 100);

	public TabelaArquivosProgressRenderer() {
		super();
		setOpaque(true);
		progressBar.setBorder(BorderFactory.createEmptyBorder(1,1,1,1));
	}

	public Component getTableCellRendererComponent(JTable table, Object value,
			boolean isSelected, boolean hasFocus, int row, int column) {
		
		Integer i = (Integer)value;
		String text = "Finalizado!";
		
		if (i == null)
			i = 0;
		
		if(i < 0)
			text = "Cancelado";
		
		else if(i < 100) {
			progressBar.setValue(i);
			return progressBar;
		}
		
		super.getTableCellRendererComponent(table, text, isSelected, hasFocus, row, column);
		return this;
	}
	
	@Override public void updateUI() {
        super.updateUI();
    }
}
